/*
 * Copyright (c), 
 * All rights reserved.
 *
 * Change Logs:
 * Date         Author      Action
 * 2019/05/xx   zck         Create this file
 */


/**
 * @file 	drv_rcc.c
 * @brief 	时钟树配置
 * @details 
 * 
 */

#include "stm32f4xx_rcc.h"
#include "stm32f4xx_flash.h"

void RCC_ConfigTo168(void)
{
	ErrorStatus errStatus;

	RCC_DeInit();
	RCC_HSEConfig(RCC_HSE_ON);
	errStatus = RCC_WaitForHSEStartUp();

	if (SUCCESS == errStatus)
	{
		// FLASH预取缓存功能使能
		FLASH_PrefetchBufferCmd(ENABLE);
		FLASH_SetLatency(FLASH_Latency_5);

		RCC_HCLKConfig(RCC_SYSCLK_Div1);
		RCC_PCLK1Config(RCC_HCLK_Div4);
		RCC_PCLK2Config(RCC_HCLK_Div2);

		// HSE时钟8MHz/8*336/2 = 168
		// 336/7 = 48
		RCC_PLLConfig(RCC_PLLSource_HSE, 8, 336, 2, 7);
		RCC_PLLCmd(ENABLE);
		while (SET != RCC_GetFlagStatus(RCC_FLAG_PLLRDY));

		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
		while (0x08 != RCC_GetSYSCLKSource());
	}
}

